package com.jiao.testdemo.pattern;

/**
 * @version V1.0
 * @className: Singleton
 * @date 2024/11/11 16:50
 */
public class Singleton {

    // 类加载时不创建实例
    private static volatile Singleton instance;


    private Singleton() {

    }

    // 提供全局访问点，使用双重检查锁定机制保证线程安全
    public static Singleton getInstance() {
        if (instance == null) {
            synchronized (Singleton.class) {
                if (instance == null) {
                    instance = new Singleton();
                }
            }
        }
        return instance;
    }

}
